package com.hanthink.web.controller.pc;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.system.domain.pc.EmResourceCall;
import com.hanthink.system.service.ISysRoleService;
import com.hanthink.system.service.pc.IEmResourceCallService;

/**
 * 资源呼叫维护Controller
 * 
 * @author hanthink
 * @date 2021-01-25
 */
@RestController
@RequestMapping("/equipment/call")
public class EmResourceCallController extends BaseController
{
    @Autowired
    private IEmResourceCallService emResourceCallService;
    
    @Autowired
    private ISysRoleService roleService;

    /**
     * 查询资源呼叫维护列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmResourceCall emResourceCall)
    {
        startPage();
        List<EmResourceCall> list = emResourceCallService.selectEmResourceCallList(emResourceCall);
        return getDataTable(list);
    }

    /**
     * 呼叫类型数据字典
     */
    @GetMapping("/dictDataList")
    public TableDataInfo dictDataList(EmResourceCall emResourceCall)
    {
        startPage();
        List<EmResourceCall> list = emResourceCallService.selectEmResourceCallList(emResourceCall);
        return getDataTable(list);
    }
    
    /**
     * 导出资源呼叫维护列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:export')")
    @Log(title = "资源呼叫维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmResourceCall emResourceCall)
    {
        List<EmResourceCall> list = emResourceCallService.selectEmResourceCallList(emResourceCall);
        ExcelUtil<EmResourceCall> util = new ExcelUtil<EmResourceCall>(EmResourceCall.class);
        return util.exportExcel(list, "call");
    }

    /**
     * 获取资源呼叫维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:query')")
    @GetMapping(value = { "/", "/{id}" })
    public AjaxResult getInfo(@PathVariable(value = "id" , required = false) Long id)
    {
    	AjaxResult ajax = AjaxResult.success();
//    	ajax.put("roles", roleService.selectRoleAll());
//    	if (StringUtils.isNotNull(id))
//        {
//            ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
//            ajax.put("postIds", postService.selectPostListByUserId(userId));
//            ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
//        }
//        return ajax;
        return AjaxResult.success(emResourceCallService.selectEmResourceCallById(id));
    }

    /**
     * 新增资源呼叫维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:add')")
    @Log(title = "资源呼叫维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmResourceCall emResourceCall)
    {
        return toAjax(emResourceCallService.insertEmResourceCall(emResourceCall));
    }

    /**
     * 修改资源呼叫维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:edit')")
    @Log(title = "资源呼叫维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmResourceCall emResourceCall)
    {
        return toAjax(emResourceCallService.updateEmResourceCall(emResourceCall));
    }

    /**
     * 删除资源呼叫维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:call:remove')")
    @Log(title = "资源呼叫维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emResourceCallService.deleteEmResourceCallByIds(ids));
    }
}
